
# class Dog(object):
#
#     name = "stupid dog"
#
#     def __init__(self,name):
#         self.name = name
#
#     @classmethod
#     def eat(self):
#         print(self) # <class '__main__.Dog'> self 是个类变量 不是实例变量
#         print("dog %s is eating..."% self.name)
#
#     @classmethod
#     def run(cls): # 定义好装饰器@classmethod之后，再定义方法括号里默认变量名就变了 不是实例，而是类本身
#         print(cls)
#
# d = Dog("Mjj")
# d.eat()
# print(Dog)
# d.run()

class Student(object):

    stu_num = 0

    def __init__(self,name):
        self.name = name
        # self.stu_num += 1 # 实际是在对实例赋值
        Student.stu_num += 1 # 对类的变量赋值
        print("生成了一个新学生，",name,self.stu_num)


s1 = Student("Mjj")
s2 = Student("Jack")
s3 = Student("Alex")

print(Student.stu_num)

